import { _decorator, Component, misc, Node, UITransform, v3, view } from "cc";
import { gameGlobalStatus } from "./GameGlobalStatus";
import { nodePoolManager } from "./Manager/NodePoolManager";
const { ccclass, property } = _decorator;

@ccclass("BulletScript")
export class BulletScript extends Component {
  _isEnemyBullet: boolean = false;
  _direction: number = 2;

  start() {}

  show(isEnemyBullet?: boolean, direction?: number) {
    if (isEnemyBullet) {
      this._isEnemyBullet = isEnemyBullet;
    }

    if (direction) {
      this._direction = direction;
    }
  }

  update(deltaTime: number) {
    let pos = this.node.position;
    let uiScreenHeight = gameGlobalStatus.uiScreenHeight;

    if (!this._isEnemyBullet) {
      let moveLength = pos.y + gameGlobalStatus.bulletSpeed;
      this.node.setPosition(pos.x, moveLength);

      if (moveLength >= uiScreenHeight) {
        nodePoolManager.putNode(this.node);
      }
    }
  }
}
